﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="Rect.cs" company="">
//   
// </copyright>
// <summary>
//   The rect.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Graphix.Elements
{
    using System.Drawing;

    using SvgNet.SvgGdi;

    /// <summary>
    /// The rect.
    /// </summary>
    public class Rect : BaseElement
    {
        #region Fields

        /// <summary>
        /// The border.
        /// </summary>
        public bool Border { get; set; }

        /// <summary>
        /// The border width.
        /// </summary>
        public float BorderWidth { get; set; }

        /// <summary>
        /// The fill.
        /// </summary>
        public bool Fill = true;

        /// <summary>
        /// The container.
        /// </summary>
        protected RectangleF container;

        #endregion

        #region Constructors and Destructors

        /// <summary>
        /// Initializes a new instance of the <see cref="Rect"/> class.
        /// </summary>
        /// <param name="rectangle">
        /// The rectangle.
        /// </param>
        /// <param name="color">
        /// The color.
        /// </param>
        public Rect(RectangleF rectangle, Color color)
            : this(rectangle, new SolidBrush(color))
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="Rect"/> class.
        /// </summary>
        /// <param name="x">
        /// The x.
        /// </param>
        /// <param name="y">
        /// The y.
        /// </param>
        /// <param name="width">
        /// The width.
        /// </param>
        /// <param name="height">
        /// The height.
        /// </param>
        /// <param name="color">
        /// The color.
        /// </param>
        public Rect(float x, float y, float width, float height, Color color)
            : this(new RectangleF(x, y, width, height), new SolidBrush(color))
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="Rect"/> class.
        /// </summary>
        /// <param name="x">
        /// The x.
        /// </param>
        /// <param name="y">
        /// The y.
        /// </param>
        /// <param name="width">
        /// The width.
        /// </param>
        /// <param name="height">
        /// The height.
        /// </param>
        /// <param name="color">
        /// The color.
        /// </param>
        public Rect(float x, float y, float width, float height, Brush color = null)
            : this(new RectangleF(x, y, width, height), color)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="Rect"/> class.
        /// </summary>
        /// <param name="rectangle">
        /// The rectangle.
        /// </param>
        /// <param name="color">
        /// The color.
        /// </param>
        public Rect(RectangleF rectangle, Brush color = null)
            : base(rectangle.X, rectangle.Y, color)
        {
            this.container = rectangle;
            this.Border = true;
            this.BorderWidth = 1;
        }

        #endregion

        #region Public Properties

        /// <summary>
        /// Gets or sets the fill color.
        /// </summary>
        public Brush FillColor { get; set; }

        #endregion

        #region Public Methods and Operators

        /// <summary>
        /// The draw.
        /// </summary>
        /// <param name="graphics">
        /// The graphics.
        /// </param>
        public override void Draw(IGraphics graphics)
        {
            if (this.Fill)
            {
                graphics.FillRectangle(this.FillColor ?? this.Color, this.Position.X,
                    this.Position.Y,
                    this.container.Width, this.container.Height, this.Attributes);
            }

            if (this.Border)
            {
                graphics.DrawRectangle(new Pen(this.Color) { Width = this.BorderWidth },
                    this.Position.X, this.Position.Y,
                    this.container.Width, this.container.Height, this.Attributes);
            }
        }

        #endregion
    }
}